package org.istt.web;

import org.apache.commons.lang.math.NumberUtils;
import org.istt.domain.Exchange;
import org.istt.service.ExchangeManager;

import com.opensymphony.xwork2.ActionContext;

/**
 * @author Huy
 *
 */
public class ExchangeAction extends BaseAction<ExchangeManager, Exchange, Long> {
	private String fileId;
	private String userId;
	private String comment;
	private String exchangeId;
	private Exchange exchange;
	/**
	 * 
	 */
	private static final long serialVersionUID = 9012754123343759656L;
	

	@Override
	public Long getId() {
		Long id = NumberUtils.toLong(exchangeId);
		if (id == 0) return null;
		return id;
	}


	@Override
	protected void setSaveMessage() {
        ActionContext.getContext().getSession().put("message", 
                getText("Exchange.saved"));
	}

	@Override
	protected void setDeleteMessage() {
        ActionContext.getContext().getSession().put("message", 
                getText("Exchange.deleted"));
	}

	/**
	 * @return the userId
	 */
	public String getUserId() {
		return userId;
	}

	/**
	 * @param comment the comment to set
	 */
	public void setComment(String comment) {
		this.comment = comment;
	}

	/**
	 * @return the comment
	 */
	public String getComment() {
		if (entity!=null) {
			return entity.getComment();
		}
		return comment;
	}
	@Override
	public String save() {
		if (log.isDebugEnabled()) {
            log.debug("entering 'save' method");
        }
        
        entity = getEntity();
        //Set status to new
        entity.setStatus(false);
        
        setSaveMessage();
                
        return SUCCESS;
	}


	public void setExchangeId(String exchangeId) {
		this.exchangeId = exchangeId;
	}
	public String getExchangeId() {
		return exchangeId;
	}

	public void setExchange(Exchange exchange) {
		this.exchange = exchange;
	}

	public Exchange getExchange() {
		return exchange;
	}

	public String getFileId() {
		return fileId;
	}

}
